home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / cfb / cfbzerarc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-15  |  5.3 KB  |  204 lines

  1. /************************************************************
  2. Copyright 1989 by The Massachusetts Institute of Technology
  3.  
  4. Permission to use, copy, modify, and distribute this
  5. software and its documentation for any purpose and without
  6. fee is hereby granted, provided that the above copyright
  7. notice appear in all copies and that both that copyright
  8. notice and this permission notice appear in supporting
  9. documentation, and that the name of MIT not be used in
  10. advertising or publicity pertaining to distribution of the
  11. software without specific prior written permission.
  12. M.I.T. makes no representation about the suitability of
  13. this software for any purpose. It is provided "as is"
  14. without any express or implied warranty.
  15.  
  16. ********************************************************/
  17.  
  18. /* $XConsortium: cfbzerarc.c,v 5.16 89/11/25 15:22:46 rws Exp $ */
  19.  
  20. /* Derived from:
  21.  * "Algorithm for drawing ellipses or hyperbolae with a digital plotter"
  22.  * by M. L. V. Pitteway
  23.  * The Computer Journal, November 1967, Volume 10, Number 3, pp. 282-289
  24.  */
  25.  
  26. #include "X.h"
  27. #include "Xprotostr.h"
  28. #include "miscstruct.h"
  29. #include "gcstruct.h"
  30. #include "pixmapstr.h"
  31. #include "scrnintstr.h"
  32. #include "cfb.h"
  33. #include "cfbmskbits.h"
  34. #include "mizerarc.h"
  35.  
  36. #if PPW == 4
  37.  
  38. extern void miPolyArc(), miZeroPolyArc();
  39.  
  40. static void
  41. cfbZeroArcSS8Copy(pDraw, pGC, arc)
  42.     DrawablePtr pDraw;
  43.     GCPtr pGC;
  44.     xArc *arc;
  45. {
  46.     miZeroArcRec info;
  47.     Bool do360;
  48.     register int x;
  49.     char *addrb;
  50.     register char *yorgb, *yorgob;
  51.     register unsigned long pixel = pGC->fgPixel;
  52.     register int yoffset;
  53.     int nlwidth, dyoffset;
  54.     register int y, a, b, d, mask;
  55.     register int k1, k3, dx, dy;
  56.  
  57.     if (pDraw->type == DRAWABLE_WINDOW)
  58.     {
  59.     addrb = (char *)
  60.         (((PixmapPtr)(pDraw->pScreen->devPrivate))->devPrivate.ptr);
  61.     nlwidth = (int)
  62.         (((PixmapPtr)(pDraw->pScreen->devPrivate))->devKind);
  63.     }
  64.     else
  65.     {
  66.     addrb = (char *)(((PixmapPtr)pDraw)->devPrivate.ptr);
  67.     nlwidth = (int)(((PixmapPtr)pDraw)->devKind);
  68.     }
  69.     do360 = miZeroArcSetup(arc, &info, TRUE);
  70.     yorgb = addrb + ((info.yorg + pDraw->y) * nlwidth);
  71.     yorgob = addrb + ((info.yorgo + pDraw->y) * nlwidth);
  72.     info.xorg += pDraw->x;
  73.     info.xorgo += pDraw->x;
  74.     MIARCSETUP();
  75.     yoffset = y ? nlwidth : 0;
  76.     dyoffset = 0;
  77.     mask = info.initialMask;
  78.     if (!(arc->width & 1))
  79.     {
  80.     if (mask & 2)
  81.         *(yorgb + info.xorgo) = pixel;
  82.     if (mask & 8)
  83.         *(yorgob + info.xorgo) = pixel;
  84.     }
  85.     if (!info.end.x || !info.end.y)
  86.     {
  87.     mask = info.end.mask;
  88.     info.end = info.altend;
  89.     }
  90.     if (do360 && (arc->width == arc->height) && !(arc->width & 1))
  91.     {
  92.     register int xoffset = nlwidth;
  93.     char *yorghb = yorgb + (info.h * nlwidth) + info.xorg;
  94.     char *yorgohb = yorghb - info.h;
  95.  
  96.     yorgb += info.xorg;
  97.     yorgob += info.xorg;
  98.     yorghb += info.h;
  99.     while (1)
  100.     {
  101.         *(yorgb + yoffset + x) = pixel;
  102.         *(yorgb + yoffset - x) = pixel;
  103.         *(yorgob - yoffset - x) = pixel;
  104.         *(yorgob - yoffset + x) = pixel;
  105.         if (a < 0)
  106.         break;
  107.         *(yorghb - xoffset - y) = pixel;
  108.         *(yorgohb - xoffset + y) = pixel;
  109.         *(yorgohb + xoffset + y) = pixel;
  110.         *(yorghb + xoffset - y) = pixel;
  111.         xoffset += nlwidth;
  112.         MIARCCIRCLESTEP(yoffset += nlwidth;);
  113.     }
  114.     yorgb -= info.xorg;
  115.     yorgob -= info.xorg;
  116.     x = info.w;
  117.     yoffset = info.h * nlwidth;
  118.     }
  119.     else if (do360)
  120.     {
  121.     while (y < info.h || x < info.w)
  122.     {
  123.         MIARCOCTANTSHIFT(dyoffset = nlwidth;);
  124.         *(yorgb + yoffset + info.xorg + x) = pixel;
  125.         *(yorgb + yoffset + info.xorgo - x) = pixel;
  126.         *(yorgob - yoffset + info.xorgo - x) = pixel;
  127.         *(yorgob - yoffset + info.xorg + x) = pixel;
  128.         MIARCSTEP(yoffset += dyoffset;, yoffset += nlwidth;);
  129.     }
  130.     }
  131.     else
  132.     {
  133.     while (y < info.h || x < info.w)
  134.     {
  135.         MIARCOCTANTSHIFT(dyoffset = nlwidth;);
  136.         if ((x == info.start.x) || (y == info.start.y))
  137.         {
  138.         mask = info.start.mask;
  139.         info.start = info.altstart;
  140.         }
  141.         if (mask & 1)
  142.         *(yorgb + yoffset + info.xorg + x) = pixel;
  143.         if (mask & 2)
  144.         *(yorgb + yoffset + info.xorgo - x) = pixel;
  145.         if (mask & 4)
  146.         *(yorgob - yoffset + info.xorgo - x) = pixel;
  147.         if (mask & 8)
  148.         *(yorgob - yoffset + info.xorg + x) = pixel;
  149.         if ((x == info.end.x) || (y == info.end.y))
  150.         {
  151.         mask = info.end.mask;
  152.         info.end = info.altend;
  153.         }
  154.         MIARCSTEP(yoffset += dyoffset;, yoffset += nlwidth;);
  155.     }
  156.     }
  157.     if ((x == info.start.x) || (y == info.start.y))
  158.     mask = info.start.mask;
  159.     if (mask & 1)
  160.     *(yorgb + yoffset + info.xorg + x) = pixel;
  161.     if (mask & 4)
  162.     *(yorgob - yoffset + info.xorgo - x) = pixel;
  163.     if (arc->height & 1)
  164.     {
  165.     if (mask & 2)
  166.         *(yorgb + yoffset + info.xorgo - x) = pixel;
  167.     if (mask & 8)
  168.         *(yorgob - yoffset + info.xorg + x) = pixel;
  169.     }
  170. }
  171.  
  172. void
  173. cfbZeroPolyArcSS8Copy(pDraw, pGC, narcs, parcs)
  174.     register DrawablePtr    pDraw;
  175.     GCPtr    pGC;
  176.     int        narcs;
  177.     xArc    *parcs;
  178. {
  179.     register xArc *arc;
  180.     register int i;
  181.     BoxRec box;
  182.     RegionPtr cclip;
  183.  
  184.     cclip = ((cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr))->pCompositeClip;
  185.     for (arc = parcs, i = narcs; --i >= 0; arc++)
  186.     {
  187.     if (miCanZeroArc(arc))
  188.     {
  189.         box.x1 = arc->x + pDraw->x;
  190.         box.y1 = arc->y + pDraw->y;
  191.         box.x2 = box.x1 + (int)arc->width + 1;
  192.         box.y2 = box.y1 + (int)arc->height + 1;
  193.         if ((*pDraw->pScreen->RectIn)(cclip, &box) == rgnIN)
  194.         cfbZeroArcSS8Copy(pDraw, pGC, arc);
  195.         else
  196.         miZeroPolyArc(pDraw, pGC, 1, arc);
  197.     }
  198.     else
  199.         miPolyArc(pDraw, pGC, 1, arc);
  200.     }
  201. }
  202.  
  203. #endif
  204.